package com.itheima.domain;

public class Student implements Comparable<Student> {

    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Student o) {//this   o
        //按规矩写  按年龄比较
        //插入的元素是this
        //已经在集合中的是o
        /*System.out.println("This:"+this);
        System.out.println("o:"+o);*/
        //正序  this-o
        //倒叙  o-this
        int result = this.age - o.age;//主要条件 先按照年龄的正序排
        result=result==0?this.name.compareTo(o.name):result;//如果年龄相同  按照姓名的先后顺序排
        return  result;
    }
}
